package com.person.leetcode.editor.cn;

/**
  * 7.整数反转
  * 2022-04-26 16:40:52
**/
public class Sequence_0007_ReverseInteger {
    public static void main(String[] args) {
        Solution solution = new Sequence_0007_ReverseInteger().new Solution();
    }
    //leetcode submit region begin(Prohibit modification and deletion)
class Solution {
        public int reverse(int x) {
            int result = 0;
            while(x != 0) {
                int tmp = result; // 保存计算之前的结果
                result = (result * 10) + (x % 10);
                x /= 10;
                // 将计算之后的结果 / 10，判断是否与计算之前相同，如果不同，证明发生溢出，返回0
                if (result / 10 != tmp) return 0;
            }

            return result;
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}
